package com.kabigon.tiny.exception;

import com.kabigon.tiny.constant.IResponseEnum;
import lombok.Getter;

/**
 * @author xu.biao
 * @version v1.0
 * @Package com.kabigon.tiny.exception
 * @data 2022/5/6 22:59
 */
@Getter
public class BaseException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    /**
     * 返回码
     */
    protected IResponseEnum responseEnum;

    /**
     * 异常信息参数
     */
    protected Object[] args;

    public BaseException(IResponseEnum responseEnum) {
        super(responseEnum.getMessage());
        this.responseEnum = responseEnum;
    }

    public BaseException(IResponseEnum responseEnum, Object[] args, String message) {
        super(message);
        this.responseEnum = responseEnum;
        this.args = args;
    }

    public BaseException(IResponseEnum responseEnum, Object[] args, String message, Throwable cause) {
        super(message, cause);
        this.responseEnum = responseEnum;
        this.args = args;
    }

    public BaseException(int code, String message) {
        super(message);
        this.responseEnum = new IResponseEnum() {
            @Override
            public int getCode() {
                return code;
            }

            @Override
            public String getMessage() {
                return message;
            }
        };
    }


}
